package v1


type Codes struct {
	SUCCESS   int
	FAILED    int
	NoAuth int
	CnMessage map[int]string
	EnMessage map[int]string
	LANG      string
}

var ApiCode = &Codes{
	SUCCESS: 200,
	FAILED:  400,
	NoAuth : 401,
	LANG:    "cn",
}

func init() {
	ApiCode.CnMessage = map[int]string{
		ApiCode.SUCCESS: "操作成功",
		ApiCode.FAILED:  "操作失败",
		ApiCode.NoAuth : "用户jwt错误",
	}
	ApiCode.EnMessage = map[int]string{
		ApiCode.SUCCESS: "succeed",
		ApiCode.FAILED:  "failed",
		ApiCode.NoAuth : "auth failed",
	}
}

func (c *Codes) GetMessage(code int) string {
	if c.LANG == "cn" {
		message, ok := c.CnMessage[code]
		if !ok {
			return ""
		}
		return message
	} else {
		message, ok := c.EnMessage[code]
		if !ok {
			return ""
		}
		return message
	}
}
